/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.webaccess.retailws.Action;

import com.webaccess.retailws.Bean.DealBean;
import com.webaccess.retailws.Bean.ProductBean;
import com.webaccess.retailws.Delegate.CategoryDelegate;
import com.webaccess.retailws.Delegate.DealDelegate;
import com.webaccess.retailws.Delegate.ProductDelegate;
import com.webaccess.retailws.Util.CommonUtil;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.actions.DispatchAction;

/**
 *
 * @author Owner
 */
public class DealDispatchAction extends DispatchAction {

    private String SUCCESS = "success";
    ActionMessages errors = null;
    CommonUtil commUtil = new CommonUtil();
    DealDelegate dealDelegateObj = null;
    ProductDelegate prodDelegate = null;
    CategoryDelegate categDelegate = null;
    ProductBean prodBean = null;
    DealBean dealBeanObj = null;

    public ActionForward deleteDeal(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        dealDelegateObj = new DealDelegate();
        categDelegate = new CategoryDelegate();
        dealBeanObj = new DealBean();
        Long dealId = 0L;
        try {
            commUtil.getTopRightListMap(request);
            dealId = Long.parseLong(request.getParameter("dealId"));
            boolean isDealDeleted = dealDelegateObj.deleteDeal(dealId);
            if (isDealDeleted == true) {
                request.setAttribute("subCategList", categDelegate.getSubCategoryLHMap());
                DealBean[] dealList = dealDelegateObj.getAllDeal();
                request.setAttribute("dealList", dealList);
                SUCCESS = "showdealoftheday";
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            return mapping.findForward(SUCCESS);
        }
    }

    public ActionForward showEditDeal(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        dealDelegateObj = new DealDelegate();
        categDelegate = new CategoryDelegate();
        dealBeanObj = new DealBean();
        Long dealId = 0L;
        try {
            commUtil.getTopRightListMap(request);
            dealId = Long.parseLong(request.getParameter("dealId"));
            dealBeanObj = dealDelegateObj.getDealDetails(dealId);
            request.setAttribute("dealDetails", dealBeanObj);
            request.setAttribute("subCategList", categDelegate.getSubCategoryLHMap());
            DealBean[] dealList = dealDelegateObj.getAllDeal();
            request.setAttribute("dealList", dealList);
            SUCCESS = "showdealoftheday";
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            return mapping.findForward(SUCCESS);
        }
    }

    public ActionForward getProductDetails(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        prodDelegate = new ProductDelegate();
        categDelegate = new CategoryDelegate();
        prodBean = new ProductBean();
        Long dealProductId = 0L;
        try {
            commUtil.getTopRightListMap(request);
            dealProductId = Long.parseLong(request.getParameter("dealProductId"));
            prodBean = prodDelegate.getProduct(dealProductId);
            request.setAttribute("productDetail", prodBean);
            request.setAttribute("subCategList", categDelegate.getSubCategoryLHMap());
            DealBean[] dealList = dealDelegateObj.getAllDeal();
            request.setAttribute("dealList", dealList);
            SUCCESS = "showdealoftheday";
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            return mapping.findForward(SUCCESS);
        }
    }
}
